package com.example.service.impl;

import com.example.common.enums.ResultCodeEnum;
import com.example.common.exception.BusinessException;
import com.example.domain.CultureProject;
import com.example.mapper.CultureDeclareMapper;
import com.example.service.CultureDeclareService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Service
public class CultureDeclareServiceImpl implements CultureDeclareService {
    @Autowired
    private CultureDeclareMapper cultureDeclareMapper;

    @Override
    public void addCulture(CultureProject cultureProject) {
        cultureProject.setCreatedAt(LocalDateTime.now());
        cultureProject.setUpdatedAt(LocalDateTime.now());
        int i = cultureDeclareMapper.addCulture(cultureProject);

        if (i == 0) {
            throw new BusinessException(ResultCodeEnum.SYSTEM_ERROR);
        }
    }

    @Override
    public List<CultureProject> queryCulture(CultureProject cultureProject) {
        return cultureDeclareMapper.queryCulture(cultureProject);
    }

    @Override
    public List<Map<String, Long>> queryCultureCategory() {
        return cultureDeclareMapper.queryCultureCategory();
    }
}
